﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Drawing.Drawing2D;


namespace Grizzy_X
{
    public partial class Childform : Form
    {
        public Viewer curViewer;

        public Childform()
        {
            InitializeComponent();
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);   //   禁止擦除背景.
            SetStyle(ControlStyles.DoubleBuffer, true);           //   双缓冲   
        }
        public PictureBox Temp;
        public PictureBox TempBase;
        //public Bitmap noselect;

        public void DisplayLegend()
        {
            this.Refresh();
            FlowLayoutPanel LegendDisplayPanel = new FlowLayoutPanel();
            LegendDisplayPanel.Name = "LegendDisplayPanel";
            LegendDisplayPanel.Width = 200;
            LegendDisplayPanel.Height = 200;
            LegendDisplayPanel.BackColor = Color.Gray;
            Controller.FindLayer(Controller.CurrentID).Controls.Add(LegendDisplayPanel);
            LegendDisplayPanel.BackColor = Color.White;
            
            Label label = new Label();
            label.Location = new Point(100, 10);
            label.Text = "图例";
            label.Font = new Font("SimHei", 15);
            label.ForeColor = Color.Black;
            LegendDisplayPanel.Controls.Add(label);

            DataGridView legendDatagridview = new DataGridView();
            legendDatagridview.Location = new Point(10, 30);
            legendDatagridview.AllowUserToAddRows = false;
            legendDatagridview.AllowUserToDeleteRows = false;
            legendDatagridview.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            //legendDatagridview.
            legendDatagridview.RowHeadersVisible = false;
            legendDatagridview.ColumnHeadersVisible = false;
            legendDatagridview.BackgroundColor = Color.White;
            legendDatagridview.BorderStyle = BorderStyle.None;
            legendDatagridview.GridColor = Color.White;
            legendDatagridview.ReadOnly = true;
            legendDatagridview.ShowEditingIcon = false;
            //legendDatagridview.RowsDefaultCellStyle 
            legendDatagridview.BackgroundColor = Color.AliceBlue;
         

            DataGridViewImageColumn clm1 = new DataGridViewImageColumn();
            DataGridViewTextBoxColumn clm2 = new DataGridViewTextBoxColumn();
            clm1.Width = 90;
            clm2.Width = 90;
            legendDatagridview.Columns.Add(clm1);
            legendDatagridview.Columns.Add(clm2);
            LegendDisplayPanel.Controls.Add(legendDatagridview);

            for (int i = 0; i < Controller.MapLegends.Count; i++)
            {
                if (Controller.MapLegends[i].Visible == true)
                {
                    legendDatagridview.Rows.Add(new DataGridViewRow());
                    Image image = new Bitmap(50,50);

                    switch (Controller.MapLegends[i].Legend_Type)
                    {
                        case CLegend.LegendType.CPointLegend:
                            image = ((CPointLegend)Controller.MapLegends[i]).cpointlegend;
                            break;
                        case CLegend.LegendType.CLineLegend:
                            {
                                CLineLegend legend = (CLineLegend)Controller.MapLegends[i];
                                image = new Bitmap(50, 50);
                                Graphics gra = Graphics.FromImage(image);
                                Pen pen = new Pen(legend.color, (float)(legend.line_weight));
                                if (legend.Line_Style == CLineLegend.LineStyle.solidline)
                                    pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
                                else if (legend.Line_Style == CLineLegend.LineStyle.dashline)
                                {
                                    float[] dashValues = { 3, 3 };
                                    pen.DashPattern = dashValues;
                                }
                                gra.DrawLine(pen, 0, 25, 50, 25);
                                gra.Dispose();
                                pen.Dispose();
                                break;
                            }
                        case CLegend.LegendType.CPolygonLegend:
                            {
                                CPolygonLegend legend = (CPolygonLegend)Controller.MapLegends[i];
                                image = new Bitmap(50, 50);
                                Graphics gra = Graphics.FromImage(image);
                                Pen pen = new Pen(legend.border_color, (float)(legend.border_weight));
                                if (legend.Border_Style == CPolygonLegend.BorderStyle.solidline)
                                    pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
                                else if (legend.Border_Style == CPolygonLegend.BorderStyle.dashline)
                                {
                                    float[] dashValues = { 3, 3 };
                                    pen.DashPattern = dashValues;
                                }
                                SolidBrush brush;
                                if (legend.Fill_Style == CPolygonLegend.FillStyle.solid)
                                {
                                    brush = new SolidBrush(legend.fill_color);
                                }
                                else 
                                {
                                    brush = new SolidBrush(Color.Transparent);
                                }
                                gra.DrawRectangle(pen, 10, 10, 35, 35);
                                gra.FillRectangle(brush,10,10,35,35);
                                gra.Dispose();
                                pen.Dispose();
                                brush.Dispose();
                                break;
                            }
                        /*case CLegend.LegendType.CTextLegend:
                            {
                                CTextLegend legend = (CTextLegend)Controller.MapLegends[i];
                                image = new Bitmap(50, 50);
                                Graphics gra = Graphics.FromImage(image);
                                SolidBrush brush = new SolidBrush(legend.string_Color);
                                gra.DrawString("Grizzy-X",legend.font,brush,25,25);

                                gra.Dispose();
                                brush.Dispose();
                                break;

                            }*/
                    }
                    legendDatagridview.Rows[i].Cells[0].Value = image;
                    legendDatagridview.Rows[i].Cells[1].Value = Controller.MapLegends[i].Title + "[" + Controller.MapLegends[i].Subtitle + "]";
                }
            }
            this.Refresh();
        }

        private void Childform_SizeChanged(object sender, EventArgs e)
        {
            if (this.FormBorderStyle == FormBorderStyle.None)
            {
                panelbase.Width = this.Width;
                panelbase.Height = this.Height;            
                Controller.View_Height = panelbase.Height;
                Controller.View_Width = panelbase.Width;

            }
            else
            {
                panelbase.Width = this.Width - 3;
                panelbase.Height = this.Height - 24;
                Controller.View_Height = panelbase.Height;
                Controller.View_Width = panelbase.Width;
            }
            Controller.View_Height = panelbase.Height;
            Controller.View_Width = panelbase.Width;
            Controller.Blank = new Bitmap(Controller.View_Width, Controller.View_Height);
        }

         public List<CPoint> Cpointlist;
         public List<CLine> Clinelist;
         public List<CPolygon> Cpolygonlist;
         public List<CText> Ctextlist;
         public bool dclick=true;
         public bool click = false;
         public bool isdown=false;
         public bool continuedraw=false;

         private Point m_startPoint = Point.Empty;                           //初始化缓存起始点
         //public string childtext = null;
         public int current_objectnum=0;

         private void Childform_Load(object sender, EventArgs e)
         {
             panelbase.Width = this.Width;
             panelbase.Height = this.Height;
             curViewer = new Viewer();
             curViewer.initializeViewer(1, 0, Controller.MyMap.Height);
         }
         public void AddBase()
         {
             Controller.MyMap.Base_Order.Insert(0, Controller.CountBase);
             PictureBox Base = new PictureBox();
             Base.Name = "Base" + Convert.ToString(Controller.CountBase);
             Base.Size = panelbase.Size;
             Base.Location = new Point(0, 0);
             Base.BackColor = Color.Transparent;
             //No layer, no base
             if (Controller.CountLayer == 0 && Controller.CountBase == 1)
             {
                 panelbase.Controls.Add(Base);
                 TempBase=(PictureBox)(this.panelbase.Controls.Find("Base1", false))[0];
             }
              //No layer, have base
             else if (Controller.CountLayer == 0)
             {
                 TempBase.Controls.Add(Base);
                 TempBase = (PictureBox)(TempBase.Controls.Find("Base" + Controller.CountBase.ToString(), false))[0];
             }
                 //have layer, no base
             else if (Controller.CountBase == 1)
             {
                 panelbase.Controls.Add(Base);
                 Base.Controls.Add((PictureBox)(this.panelbase.Controls.Find("Layer1", false))[0]);
                 TempBase = (PictureBox)(this.panelbase.Controls.Find("Base" + Controller.CountBase.ToString(), false))[0];
             }
                 //have layer, have base
             else
             {
                 TempBase.Controls.Add(Base);
                 Base.Controls.Add((PictureBox)(this.TempBase.Controls.Find("Layer1", false))[0]);
                 TempBase = (PictureBox)(TempBase.Controls.Find("Base" + Controller.CountBase.ToString(), false))[0];

             }
         }
         public void AddLayer()
         {
             Controller.CountLayer++;
             Controller.Selected = new List<int>();
             PictureBox Layer1 = new PictureBox();
             Layer1.Name = "Layer" + Convert.ToString(Controller.CountLayer);
             Layer1.BackColor = Color.Transparent;
             Layer1.Size = panelbase.Size;
             Layer1.Location = new Point(0, 0);
             if (Controller.CountLayer ==1 && Controller.CountBase==0)
             {
                 panelbase.Controls.Add(Layer1);
                 Temp = (PictureBox)(this.panelbase.Controls.Find("Layer" + Controller.CountLayer.ToString(), false))[0];
                 Controller.CurrentLayer = Controller.MyMap.Layer_List[Controller.CountLayer-1];
             }
             else if (Controller.CountLayer == 1)
             {
                 TempBase.Controls.Add(Layer1);
                 Temp = (PictureBox)(TempBase.Controls.Find("Layer" + Controller.CountLayer.ToString(), false))[0];
                 Controller.CurrentLayer = Controller.MyMap.Layer_List[Controller.CountLayer - 1];
             }
             else
             {
                 Temp.Controls.Add(Layer1);
                 Temp = (PictureBox)(Temp.Controls.Find("Layer" + Controller.CountLayer.ToString(), false))[0];
                 Controller.CurrentLayer = Controller.MyMap.Layer_List[Controller.CountLayer - 1];
             }
             Layer1.BringToFront();

             Temp.MouseClick += new MouseEventHandler(Temp_MouseClick);
             Temp.MouseMove += new MouseEventHandler(Temp_MouseMove);
             Temp.MouseDoubleClick += new MouseEventHandler(Temp_MouseDoubleClick);
             Temp.MouseDown+=new MouseEventHandler(Temp_MouseDown);
             Temp.MouseUp+=new MouseEventHandler(Temp_MouseUp);
            if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CPointLayer)
            {
                Cpointlist = new List<CPoint>();
                current_objectnum = 0;
                dclick = true;
                click = false;
            }
            if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CLineLayer)
            {
                Clinelist = new List<CLine>();
                current_objectnum = 0;
                dclick = true;
                click = false;
            }
            if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CPolygonLayer)
            {
                Cpolygonlist = new List<CPolygon>();
                current_objectnum = 0;
                dclick = true;
                click = false;
            }
            if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CTextLayer)
            {
                Ctextlist = new List<CText>();
                current_objectnum = 0;
                dclick = true;
                click = false;
            }
           
        }
        private Point start_Point = new Point();  //放大缩小时的起点和终点
        private Point end_Point = new Point();
        private List<Point> Move_trails = new List<Point>();
        private bool Select_position = false;
        private Bitmap splitbmp;
        private List<PointF> splitline = new List<PointF>();

        public bool drawisland = false;
        public bool addislandpolygon=false;
         private void Temp_MouseClick(object sender, MouseEventArgs e)
         {
              if(Controller.current_Operation == Controller.OperationStyles.SplitLine)
            {
                splitbmp = new Bitmap(Temp.Image);
                Graphics a = Graphics.FromImage(splitbmp);
                a.FillRectangle(Brushes.BlueViolet, e.X - 1, e.Y - 1, 2, 2);
                m_startPoint = new Point(e.X,e.Y);
                splitline.Add(Transformer.FromScreen(new Point(e.X, e.Y)));
                if (splitline.Count() == 2)
                {
                    click = false;
                    Controller.current_Operation = Controller.OperationStyles.Selecting;
                    splitbmp = Controller.Blank;
                    Temp.Image = ((CLineLayer)Controller.MyMap.Layer_List[Controller.MyMap.Layer_Order[0] - 1]).drawlinelayer();
                    if (!((CLineLayer)Controller.MyMap.Layer_List[Controller.MyMap.Layer_Order[0] - 1]).Line_Set[Controller.Selected[0]].Split(splitline[0], splitline[1]))
                    {
                        MainForm.pMainWin.Split.Enabled = false;
                        splitline.Clear();
                        return;
                    }
                    splitline.Clear();
                    Temp.Image = ((CLineLayer)Controller.MyMap.Layer_List[Controller.MyMap.Layer_Order[0] - 1]).drawlinelayer();
                    MainForm.pMainWin.Split.Enabled = false;
                    this.Cursor = Cursors.Default;
                    return;
                }
                click=true;
                Temp.Image = splitbmp;
            }
            //Split Polygon Mode
            if (Controller.current_Operation == Controller.OperationStyles.SplitPolygon)
            {
                Temp.ContextMenuStrip = null;
                splitbmp = new Bitmap(Temp.Image);
                Graphics a = Graphics.FromImage(splitbmp);
                //m_startPoint = new Point(e.X, e.Y);
                //splitline.Add(Transformer.FromScreen(new Point(e.X, e.Y)));
                splitline.Add(new Point(e.X, e.Y));
                for (int i = 0; i < splitline.Count; i++)
                    a.FillRectangle(Brushes.BlueViolet, splitline[i].X - 2, splitline[i].Y - 2, 4, 4);
                if(splitline.Count>=2)
                    a.DrawLines(new Pen(Color.SaddleBrown, 2),splitline.ToArray());
                if (e.Button==MouseButtons.Right)
                {
                    click = false;
                    Controller.current_Operation = Controller.OperationStyles.Selecting;
                    splitbmp = Controller.Blank;
                    Temp.Image = ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.MyMap.Layer_Order[0] - 1]).drawpolygon();
                    for (int i = 0; i < splitline.Count; i++)
                    {
                        splitline[i]=Transformer.FromScreen(new Point((int)splitline[i].X,(int)splitline[i].Y));
                    }
                    if (!((CPolygonLayer)Controller.MyMap.Layer_List[Controller.MyMap.Layer_Order[0] - 1]).Polygon_Set[Controller.Selected[0]].Split(splitline))
                    {
                        MainForm.pMainWin.Split.Enabled = false;
                        MainForm.pMainWin.EditButton();
                        splitline.Clear();
                        return;
                    }
                    splitline.Clear();
                    Temp.Image = ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.MyMap.Layer_Order[0] - 1]).drawpolygon();
                    MainForm.pMainWin.Split.Enabled = false;
                    this.Cursor = Cursors.Default;
                    return;
                }
                click = true;
                Temp.Image = splitbmp;
            }
             //若操作处于编辑状态
             if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CPolygonLayer)
             {
                 MainForm.pMainWin.snapsameedge.Enabled = true;
             }
             if (Controller.current_Operation == Controller.OperationStyles.Editing && Controller.current_Operation != Controller.OperationStyles.Zoomin && Controller.current_Operation != Controller.OperationStyles.Zoomout)
             {
                 Controller.Selected = new List<int>();
                 if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CPointLayer)
                 {
                     if (Cpointlist.Count() == 0)
                     {
                         Cpointlist.Add(new CPoint());
                         current_objectnum = Cpointlist.Count() - 1;
                         Cpointlist[current_objectnum].newCpoint(IDGenerator.PointID(),Controller.CurrentLegendIndex);
                         ((CPointLayer)Controller.MyMap.Layer_List[Controller.CurrentID-1]).Point_Set.Add(Cpointlist[current_objectnum]);
                     }
                     else if (current_objectnum == Cpointlist.Count())
                     {
                         Cpointlist.Add(new CPoint());
                         current_objectnum = Cpointlist.Count() - 1;
                         Cpointlist[current_objectnum].newCpoint(IDGenerator.PointID(), Controller.CurrentLegendIndex);
                         ((CPointLayer)Controller.MyMap.Layer_List[Controller.CurrentID-1]).Point_Set.Add(Cpointlist[current_objectnum]);
                     }
                     //pt_增加点xyToolStripMenuItem.Enabled = true;
                     pt_结束编辑ToolStripMenuItem.Enabled = true;
                     //Cpointlist[current_objectnum].LegendID = Controller.MapLegends.Count() - 1;
                     PointF real_temp=Transformer.FromScreen(new Point(e.X, e.Y));
                     Cpointlist[current_objectnum].AddPoint(real_temp);
                     Temp.Image = ((CPointLayer)Controller.MyMap.Layer_List[Controller.CurrentID-1]).drawpoint();
                 }
                 else if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CTextLayer)
                 {
                     if (MainForm.pMainWin.TextEdit.Text == null || MainForm.pMainWin.TextEdit.Text == "")
                         MessageBox.Show("请先在文本编辑框中输入文本", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                     else
                     {
                         if (Ctextlist.Count() == 0)
                         {
                             Ctextlist.Add(new CText());
                             current_objectnum = Ctextlist.Count() - 1;
                             Ctextlist[current_objectnum].newCtext(IDGenerator.TextID(), Controller.CurrentLegendIndex);
                             ((CTextLayer)Controller.MyMap.Layer_List[Controller.CurrentID-1]).AddText(Ctextlist[current_objectnum]);
                         }
                         else if (current_objectnum == Ctextlist.Count())
                         {
                             Ctextlist.Add(new CText());
                             current_objectnum = Ctextlist.Count() - 1;
                             Ctextlist[current_objectnum].newCtext(IDGenerator.TextID(), Controller.CurrentLegendIndex);
                             ((CTextLayer)Controller.MyMap.Layer_List[Controller.CurrentID-1]).AddText(Ctextlist[current_objectnum]);
                         }
                         //tx_增加文本到xyToolStripMenuItem.Enabled = true;
                         tx_结束编辑ToolStripMenuItem2.Enabled = true;
                         //Ctextlist[current_objectnum].LegendID = Controller.MapLegends.Count() - 1;
                         PointF real_temp = Transformer.FromScreen(new Point(e.X, e.Y));
                         Ctextlist[current_objectnum].addpoint_text(real_temp, MainForm.pMainWin.TextEdit.Text);
                         Temp.Image = ((CTextLayer)Controller.MyMap.Layer_List[Controller.CurrentID-1]).drawtext();
                     }
                 }
                 else
                 {
                     m_startPoint = new Point(e.X, e.Y);
                     if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CLineLayer)
                     {
                         if (Clinelist.Count() == 0)
                         {
                             Clinelist.Add(new CLine());
                             current_objectnum = Clinelist.Count() - 1;
                             Clinelist[current_objectnum].newCline(IDGenerator.LineID(), Controller.CurrentLegendIndex);
                             ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID-1]).AddLine(Clinelist[current_objectnum]);
                         }
                         else if (current_objectnum == Clinelist.Count())
                         {
                             Clinelist.Add(new CLine());
                             current_objectnum = Clinelist.Count() - 1;
                             Clinelist[current_objectnum].newCline(IDGenerator.LineID(), Controller.CurrentLegendIndex);
                             ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID-1]).AddLine(Clinelist[current_objectnum]);
                         }
                         if (dclick)
                                 Clinelist[current_objectnum].Lines.Add(new List<PointF>());
                         //ln_增加节点到xyToolStripMenuItem.Enabled = true;
                         ln_结束编辑ToolStripMenuItem1.Enabled = true;
                         //Clinelist[current_objectnum].LegendID = Controller.MapLegends.Count() - 1;                       
                         PointF real_temp = Transformer.FromScreen(new Point(e.X, e.Y));
                         Clinelist[current_objectnum].addnode(real_temp);
                         Temp.Image = ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID-1]).drawlinelayer();
                     }
                     else
                     {
                         if(Cpolygonlist.Count()==0)
                         {
                             Cpolygonlist.Add(new CPolygon());
                             current_objectnum = Cpolygonlist.Count() - 1;
                             Cpolygonlist[current_objectnum].newCpolygon(IDGenerator.PolygonID(),Controller.MapLegends.Count() - 1);
                             ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID-1]).AddPolygon(Cpolygonlist[current_objectnum]);
                         }
                         else  if (current_objectnum == Cpolygonlist.Count())
                         {
                             Cpolygonlist.Add(new CPolygon());
                             current_objectnum = Cpolygonlist.Count() - 1;
                             Cpolygonlist[current_objectnum].newCpolygon(IDGenerator.PolygonID(),Controller.MapLegends.Count() - 1);
                             ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID-1]).AddPolygon(Cpolygonlist[current_objectnum]);
                         }
                         if(dclick)
                             Cpolygonlist[current_objectnum].Polygons.Add(new List<PointF>());
                         //plgn_增加节点到xyToolStripMenuItem1.Enabled = true;
                         plgn_结束编辑ToolStripMenuItem3.Enabled = true;
                         //Cpolygonlist[current_objectnum].LegendID = Controller.MapLegends.Count() - 1;                       
                         PointF real_temp = Transformer.FromScreen(new Point(e.X, e.Y));
                         Cpolygonlist[current_objectnum].addnode(real_temp);
                         if (MainForm.pMainWin.snapsameedge.Checked == true)
                         {
                             MainForm.pMainWin.SnapPoint.Enabled = true;
                             MainForm.pMainWin.SnapEdge.Enabled = true;
                             if (Controller.snapsameedge == null)
                                 Controller.snapsameedge = new List<int>();
                             ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).snapsameegde(real_temp);
                         }
                         int index = ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set.Count() - 1;
                         Temp.Image = ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawnode(dclick, index);
                         //Temp.Image = ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID-1]).drawnode(dclick, current_objectnum);
                     }
                     dclick = false;
                     click = true;
                 }
             }
             //Selecting Mode
             if (Controller.current_Operation == Controller.OperationStyles.Selecting)
             {
                 //isdown = false;
                 if (!draggingc && !draggingnode && !draggingsimple)
                 {
                     PointF real_temp = Transformer.FromScreen(new Point(e.X, e.Y));
                     if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CPointLayer)
                     {
                       pt_复制ToolStripMenuItem.Enabled = true;
                         if (!continuedraw && !selectsimple)
                         {
                             ((CPointLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).SelectPoint(real_temp);
                             if (Controller.Selected.Count == 1)
                             {
                                 if(((CPointLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Point_Set[Controller.Selected[0]].points.Count()>1)
                                        MainForm.pMainWin.Ununion.Enabled = true;
                                 else 
                                    MainForm.pMainWin.Ununion.Enabled = false;
                             }
                             if (Controller.Selected.Count > 1)
                                 MainForm.pMainWin.Ununion.Enabled = false;
                         }
                        if (selectsimple)
                            ((CPointLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Point_Set[Controller.Selected[0]].selectsimplepoint(real_temp);
                        if (continuedraw)
                            ((CPointLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Point_Set[Controller.Selected[0]].points.Add(real_temp);
                        Temp.Image = ((CPointLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawpoint();

                     }
                     if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CLineLayer)
                     {
                         //PointF real_temp = Viewer.FromScreen(new Point(e.X, e.Y));
                         if (!continuedraw && !selectsimple)
                         {
                             ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).SelectLine(real_temp);
                             if (Controller.Selected.Count == 1)
                             {
                                 if (((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Line_Set[Controller.Selected[0]].Lines.Count() > 1)
                                     MainForm.pMainWin.Ununion.Enabled = true;
                                 else
                                     MainForm.pMainWin.Ununion.Enabled = false;                                 
                             }
                             if (Controller.Selected.Count > 1)
                                 MainForm.pMainWin.Ununion.Enabled = false;
                         }
                         if (selectsimple)
                             ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID-1]).Line_Set[Controller.Selected[0]].selectsimpleline(real_temp);
                         if (continuedraw)
                         {
                             m_startPoint = new Point(e.X, e.Y);
                             if (dclick)
                                 ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID-1]).Line_Set[Controller.Selected[0]].Lines.Add(new List<PointF>());
                             ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID-1]).Line_Set[Controller.Selected[0]].addnode(real_temp);
                             dclick = false;
                             click = true;
                         }
                         Temp.Image = ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID-1]).drawlinelayer();
                     }
                         if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CPolygonLayer)
                         {
                             if (!continuedraw&!selectsimple&&!drawisland)
                             {
                                 ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).SelectPolygon(real_temp);
                                 Temp.Image = ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawpolygon();
                                 if (Controller.Selected.Count == 1)
                                 {
                                     if (((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set[Controller.Selected[0]].Polygons.Count() > 1)
                                         MainForm.pMainWin.Ununion.Enabled = true;
                                     else
                                         MainForm.pMainWin.Ununion.Enabled = false;
                                     if (((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set[Controller.Selected[0]].Polygons.Count() == 1)
                                         MainForm.pMainWin.Island.Enabled = true;
                                     else
                                         MainForm.pMainWin.Island.Enabled = false;
                                 }
                                 if (Controller.Selected.Count > 1)
                                 {
                                     MainForm.pMainWin.Ununion.Enabled = false;
                                     MainForm.pMainWin.Island.Enabled = false;
                                 }
                             }
                             if (selectsimple)
                             {
                                 ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set[Controller.Selected[0]].selectsimplepolygon(real_temp);
                                 Temp.Image = ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawpolygon();
                             }
                             if (continuedraw)
                             {
                                 m_startPoint = new Point(e.X, e.Y);
                                 if (dclick)
                                     ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set[Controller.Selected[0]].Polygons.Add(new List<PointF>());
                                 ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set[Controller.Selected[0]].addnode(real_temp);
                                 dclick = false;
                                 click = true;
                                 Temp.Image = ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawnode(dclick, Controller.Selected[0]);
                             }
                             if (drawisland)
                             {
                                 m_startPoint = new Point(e.X, e.Y);
                                 ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawisland = true;
                                 if (dclick)
                                 {
                                     try
                                     {
                                         ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set[Controller.Selected[0]].island = new List<PointF>();
                                         ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set[Controller.Selected[0]].Polygons.Add(new List<PointF>());
                                     }
                                     catch
                                     {
                                         MessageBox.Show("请先结束编辑！");
                                         return;
                                     }
                                 }
                                 ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set[Controller.Selected[0]].island.Add(real_temp);
                                 ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set[Controller.Selected[0]].addnode(real_temp);
                                 dclick = false;
                                 click = true;
                                 Temp.Image = ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawnode(dclick, Controller.Selected[0]);
                             }
                         }
                         else if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CTextLayer)
                         {
                             if (!continuedraw && !selectsimple&&!modifytext)
                             {
                                 ((CTextLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).SelectCtext(real_temp);
                                 if (Controller.Selected.Count() == 1)
                                 {
                                     if (((CTextLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Text_Set[Controller.Selected[0]].points.Count() == 1)
                                         修改文本ToolStripMenuItem.Enabled = true;
                                 }
                                 else
                                 {
                                     修改文本ToolStripMenuItem.Enabled = false;
                                 }
                                 if (Controller.Selected.Count == 1)
                                 {
                                     if (((CTextLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Text_Set[Controller.Selected[0]].texts.Count() > 1)
                                         MainForm.pMainWin.Ununion.Enabled = true;
                                     else
                                         MainForm.pMainWin.Ununion.Enabled = false;
                                 }
                                 if (Controller.Selected.Count > 1)
                                     MainForm.pMainWin.Ununion.Enabled = false;
                             }
                             else if (selectsimple&&!modifytext)
                             {
                                 ((CTextLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Text_Set[Controller.Selected[0]].selectsimpletext(real_temp);
                                 if (Controller.selectsimple.Count() == 1)
                                 {
                                     修改文本ToolStripMenuItem.Enabled = true;
                                 }
                                 else
                                 {
                                     修改文本ToolStripMenuItem.Enabled = false;
                                 }
                             }
                             else if (continuedraw)
                             {
                                 if (MainForm.pMainWin.TextEdit.Text == null || MainForm.pMainWin.TextEdit.Text == "")
                                     MessageBox.Show("请先在文本编辑框中输入文本", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                 else
                                 {
                                     ((CTextLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Text_Set[Controller.Selected[0]].addpoint_text(real_temp, MainForm.pMainWin.TextEdit.Text);
                                 }
                             }
                             //Temp.Image = ((CTextLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawtext();
                             else if(modifytext)
                             {
                                 if (MainForm.pMainWin.TextEdit.Text == null || MainForm.pMainWin.TextEdit.Text == "")
                                     MessageBox.Show("请输入新文本", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                 else
                                 {
                                     if (((CTextLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Text_Set[Controller.Selected[0]].texts.Count() == 1)
                                     {
                                         ((CTextLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Text_Set[Controller.Selected[0]].texts[0] = MainForm.pMainWin.TextEdit.Text;
                                     }
                                     else if (Controller.selectsimple.Count() == 1)
                                     {
                                         ((CTextLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Text_Set[Controller.Selected[0]].texts[Controller.selectsimple[0]] = MainForm.pMainWin.TextEdit.Text;
                                     }
                                     ((CTextLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Text_Set[Controller.Selected[0]].updatetextboxes();
                                 }
                             }
                             Temp.Image = ((CTextLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawtext();
                         }
                         if (Controller.Selected.Count() > 0)
                             MainForm.pMainWin.Drag.Enabled = true;
                         else if(Controller.Selected.Count()==0)
                             MainForm.pMainWin.Drag.Enabled=false;
                         if (Controller.Selected.Count() <= 1)
                             MainForm.pMainWin.Union.Enabled = false;
                         else if (Controller.Selected.Count() > 1)
                             MainForm.pMainWin.Union.Enabled = true;  
                }
                 
             }
            if (Controller.current_Operation == Controller.OperationStyles.Editnode)
            {
                if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CLineLayer)
                {
                    if (!draggingnode && !addnode)
                    {
                        PointF real_temp = Transformer.FromScreen(new Point(e.X, e.Y));
                        ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Line_Set[Controller.Selected[0]].selectnodeorline(real_temp);
                        Temp.Image = ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawlinelayer();
                    }
                    if (Controller.selectlineindex.X != -1)
                        ln_增加节点到xyToolStripMenuItem.Enabled = true;
                    if (Controller.selectnodeindex.X != -1)
                    {
                        if (Controller.selectnodeindex.Y == 0 || Controller.selectnodeindex.Y == ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Line_Set[Controller.Selected[0]].Lines[Controller.selectnodeindex.X].Count() - 1)
                            ln_增加节点到xyToolStripMenuItem.Enabled = true;
                    }
                    if (addnode)
                    {
                        PointF real_temp = Transformer.FromScreen(new Point(e.X, e.Y));
                        if (Controller.selectlineindex.X != -1)
                        {
                            ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Line_Set[Controller.Selected[0]].Lines[Controller.selectlineindex.X].Insert(Controller.selectlineindex.Y + 1, real_temp);
                        }
                        if (Controller.selectnodeindex.X != -1)
                        {
                            if (Controller.selectnodeindex.Y == 0)
                                ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Line_Set[Controller.Selected[0]].Lines[Controller.selectnodeindex.X].Insert(0, real_temp);
                            else
                            {
                                ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Line_Set[Controller.Selected[0]].Lines[Controller.selectnodeindex.X].Add(real_temp);
                                Controller.selectnodeindex.Y = ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Line_Set[Controller.Selected[0]].Lines[Controller.selectnodeindex.X].Count() - 1;
                            }
                        }
                        Temp.Image = ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawlinelayer();
                    }
                }
                if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CPolygonLayer)
                {
                    if (!draggingnode && !addnode)
                    {
                        PointF real_temp = Transformer.FromScreen(new Point(e.X, e.Y));
                        ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set[Controller.Selected[0]].selectnodeorline(real_temp);
                        Temp.Image = ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawpolygon();
                    }
                    if (Controller.selectlineindex.X != -1)
                        plgn_增加节点到xyToolStripMenuItem1.Enabled = true;
                    if (addnode)
                    {
                        PointF real_temp = Transformer.FromScreen(new Point(e.X, e.Y));
                        if (Controller.selectlineindex.X != -1)
                        {
                            if (Controller.selectlineindex.Y == ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set[Controller.Selected[0]].Polygons[Controller.selectlineindex.X].Count() - 1)
                                ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set[Controller.Selected[0]].Polygons[Controller.selectlineindex.X].Add(real_temp);
                            else
                                ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set[Controller.Selected[0]].Polygons[Controller.selectlineindex.X].Insert(Controller.selectlineindex.Y + 1, real_temp);
                        }
                        Temp.Image = ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawpolygon();
                    }
                }
            }
        }

         private Point CopyToLoc;
         //漫游用
         Point p1 = new Point();
         int driftX = 0, driftY = 0;
         int mx = 0, my = 0;
         bool panselected = false;

         private void Temp_MouseMove(object sender, MouseEventArgs e)
         {
             PointF position = Transformer.FromScreen(new Point(e.X, e.Y));

             if (position.X > Controller.MyMap.Width)
             {
                 MainForm.pMainWin.toolStripStatusX.Text = "X坐标超出范围!";
             }
             else if(position.X<0)
             {
                 MainForm.pMainWin.toolStripStatusX.Text = "不在地图范围内！";
             }
             else
             {
                 MainForm.pMainWin.toolStripStatusX.Text = position.X.ToString();
             }
             if (position.Y > Controller.MyMap.Height)
             {
                 MainForm.pMainWin.toolStripStatusY.Text = "Y坐标超出范围!";
             }
             else if(position.Y<0)
             {
                 MainForm.pMainWin.toolStripStatusY.Text = "不在地图范围内!";
             }
             else
             {
                 MainForm.pMainWin.toolStripStatusY.Text = position.Y.ToString();
             }
             bool snapp = false;
             if (MainForm.pMainWin.SnapPoint.Checked == true)
             {
                 //Cursor.Position = new Point(2, 2);
                 //e.Y = 2;
                 PointF real_temp = Transformer.FromScreen(new Point(e.X, e.Y));
                 if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CLineLayer)
                 {
                     Point cursorp = new Point();
                     cursorp = ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).snapnode(real_temp);
                     if (cursorp.X != -1)
                     {
                         Cursor.Position = new Point(cursorp.X, cursorp.Y);
                         snapp = true;
                         //cursorp = new Point(-1, -1);
                     }
                 }
                 if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CPolygonLayer)
                 {
                     Point cursorp = new Point();
                     cursorp = ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).snapnode(real_temp);
                     if (cursorp.X != -1)
                     {
                         Cursor.Position = new Point(cursorp.X, cursorp.Y);
                         snapp = true;
                         //cursorp = new Point(-1, -1);
                     }
                 }
             }
             if (MainForm.pMainWin.SnapEdge.Checked == true)
             {
                 if (!snapp)
                 {
                     PointF real_temp = Transformer.FromScreen(new Point(e.X, e.Y));
                     if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CLineLayer)
                     {
                         Point cursorp = new Point();
                         cursorp = ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).snapedge(real_temp);
                         if (cursorp.X != -1)
                         {
                             Cursor.Position = new Point(cursorp.X, cursorp.Y);
                             //cursorp = new Point(-1, -1);
                         }
                     }
                     if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CPolygonLayer)
                     {
                         Point cursorp = new Point();
                         cursorp = ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).snapedge(real_temp);
                         if (cursorp.X != -1)
                         {
                             Cursor.Position = new Point(cursorp.X, cursorp.Y);
                             //cursorp = new Point(-1, -1);
                         }
                     }
                 }
             }
             if (canBeCopied == true)
             {
                 pt_粘贴ToolStripMenuItem.Enabled = true;
                 CopyToLoc = new Point(e.X, e.Y);
             }
             else pt_粘贴ToolStripMenuItem.Enabled = false;
              if (Controller.current_Operation == Controller.OperationStyles.SplitLine)
            {
                if (click)
                {
                    if (m_startPoint.X != e.X && m_startPoint.Y != e.Y)
                    {
                        splitbmp = ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawlinelayer();
                        Graphics a = Graphics.FromImage(splitbmp);
                        a.FillRectangle(Brushes.Black, m_startPoint.X - 1, m_startPoint.Y - 1, 2, 2);
                        a.DrawLine(new Pen(Color.SaddleBrown, 2), m_startPoint, new Point(e.X, e.Y));
                    }
                    //splitpoint = new Point(m_startPoint.X, m_startPoint.Y);
                    Temp.Image = splitbmp;
                }
            }
            if (Controller.current_Operation == Controller.OperationStyles.SplitPolygon)
            {
                if (click)
                {
                    splitbmp = ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawpolygon();
                    Graphics a = Graphics.FromImage(splitbmp);
                    if (splitline.Count >= 2)
                        a.DrawLines(new Pen(Color.SaddleBrown, 2), splitline.ToArray());
                    a.DrawLine(new Pen(Color.SaddleBrown, 2), splitline[splitline.Count - 1], new Point(e.X, e.Y));
                    for (int i = 0; i < splitline.Count;i++ )
                        a.FillRectangle(Brushes.BlueViolet, splitline[i].X - 2, splitline[i].Y - 2, 4, 4);
                    Temp.Image = splitbmp;
                }
            }
                if (Controller.current_Operation == Controller.OperationStyles.Editing)
                {
                    if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CLineLayer || Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CPolygonLayer)
                    {
                        if (click)
                        {
                            Graphics a = Temp.CreateGraphics();
                            if (this.m_startPoint.X != e.X && this.m_startPoint.Y != e.Y)
                            {
                                if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CLineLayer)
                                {
                                    int index = ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Line_Set.Count() - 1;
                                    Temp.Image = ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawLine(m_startPoint, new Point(e.X, e.Y), index);
                                }
                                else
                                {
                                    int index = ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set.Count() - 1;
                                    Temp.Image = ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawline(m_startPoint, new Point(e.X, e.Y), index);
                                }
                            }
                        }
                    }
                }
                else if (Controller.current_Operation == Controller.OperationStyles.Zoomin)
                {
                    if (Select_position == true)
                    {
                        Bitmap cur_Layer;
                        if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CPointLayer)
                        {
                            cur_Layer = ((CPointLayer)Controller.CurrentLayer).drawpoint();
                        }
                        else if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CLineLayer)
                        {
                            cur_Layer = ((CLineLayer)Controller.CurrentLayer).drawlinelayer();
                        }
                        else if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CPolygonLayer)
                        {
                            cur_Layer = ((CPolygonLayer)Controller.CurrentLayer).drawpolygon();
                        }
                        else
                        {
                            cur_Layer = ((CTextLayer)Controller.CurrentLayer).drawtext();
                        }
                        //注意只有底图的情况。。。

                        Graphics a = Graphics.FromImage(cur_Layer);
                        Pen blackPen = new Pen(Color.Black, 2f);
                        a.DrawRectangle(blackPen, start_Point.X, start_Point.Y, (e.X - start_Point.X), (e.Y - start_Point.Y));
                        Temp.Image = cur_Layer;
                        //cur_Layer.Dispose();
                        a.Dispose();

                        /* Point temp = new Point();
                        temp.X = e.X;
                        temp.Y = e.Y;
                        Move_trails.Add(temp);
                        if (Move_trails.Count == 1)
                        {
                            rec.DrawRectangle(Pens.Black, start_Point.X, start_Point.Y, (e.X - start_Point.X), (e.Y - start_Point.Y));
                        }
                       else
                       {
                           Pen blackPen = new Pen(Color.Black,2f);
                           Pen whitePen = new Pen(Color.White,2f);
                           rec.DrawRectangle(whitePen, start_Point.X, start_Point.Y, (Move_trails[Move_trails.Count-2].X - start_Point.X), (Move_trails[Move_trails.Count-2].Y - start_Point.Y));
                           rec.DrawImage(original, 0, 0);
                           rec.DrawRectangle(blackPen, start_Point.X, start_Point.Y, (e.X - start_Point.X), (e.Y - start_Point.Y));
                        }*/
                    }
                }

                //pan的mousemove事件目前未发挥作用
                else if (Controller.current_Operation == Controller.OperationStyles.Panning && panselected == true)
                {
                    driftX = p1.X - e.X;
                    driftY = p1.Y - e.Y;

                    if (Math.Abs(driftX) >= 10 || Math.Abs(driftY) >= 10)
                    {
                        mx = mx - driftX;
                        my = my - driftY;

                        PictureBox ZoomTemp = new PictureBox();
                        Bitmap bm;
                        Graphics g;

                        for (int i = Controller.MyMap.Layer_Order.Count() - 1; i >= 0; i--)
                        {
                            ZoomTemp = Controller.FindLayer(Controller.MyMap.Layer_Order[i]);
                            ZoomTemp.Refresh();
                            bm = new Bitmap(ZoomTemp.Image);
                            Bitmap temp = new Bitmap(Controller.View_Width, Controller.View_Height);
                            g = Graphics.FromImage(temp); ;
                            g.DrawImage(bm, mx, my);
                            //temp.Dispose();
                            //bm.Dispose();
                            //g.Dispose();
                        }

                        for (int j = Controller.MyMap.Base_Order.Count - 1; j >= 0; j--)
                        {
                            ZoomTemp = Controller.FindBase(Controller.MyMap.Base_Order[j]);
                            ZoomTemp.Refresh();
                            bm = new Bitmap(ZoomTemp.Image);
                            g = ZoomTemp.CreateGraphics();

                            g.DrawImage(bm, mx, my);
                            //bm.Dispose();
                            //g.Dispose();
                        }
                        p1.Y = e.Y;
                        p1.X = e.X;
                    }
                }
               
                else if (Controller.current_Operation == Controller.OperationStyles.Editnode)
                {
                    if (draggingnode)
                    {
                        if (isdown)
                        {
                            Point move = new Point((e.X - m_startPoint.X), (e.Y - m_startPoint.Y));
                            if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CLineLayer)
                            {
                                ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Line_Set[Controller.Selected[0]].DragNode(move);
                                Temp.Image = ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawlinelayer();
                            }
                            if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CPolygonLayer)
                            {
                                ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set[Controller.Selected[0]].DragNode(move);
                                Temp.Image = ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawpolygon();
                            }
                            m_startPoint = new Point(e.X, e.Y);
                        }
                    }
                }
                else if (Controller.current_Operation == Controller.OperationStyles.Selecting)
                {
                    if (draggingc || draggingsimple)
                    {
                        if (isdown)
                        {
                            Point move = new Point((e.X - m_startPoint.X), (e.Y - m_startPoint.Y));
                            if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CPointLayer)
                            {
                                if (draggingc)
                                {
                                    for (int i = 0; i < Controller.Selected.Count(); i++)
                                    {
                                        ((CPointLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Point_Set[Controller.Selected[i]].DragPoint(move);
                                    }
                                }
                                if (draggingsimple)
                                {            
                                        ((CPointLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Point_Set[Controller.Selected[0]].DragsimplePoint(move);
                                }
                                Bitmap noselect = ((CPointLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawnoselect();
                                Temp.Image = ((CPointLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawselectbounds(noselect);
                            }
                            if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CLineLayer)
                            {
                                if (draggingc)
                                {
                                    for (int i = 0; i < Controller.Selected.Count(); i++)
                                    {
                                        ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Line_Set[Controller.Selected[i]].DragLine(move);
                                    }
                                }
                                if (draggingsimple)
                                {
                                    ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Line_Set[Controller.Selected[0]].DragsimpleLine(move);
                                }
                                /*if (draggingnode)
                                {
                                    ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Line_Set[Controller.Selected[0]].DragNode(move);
                                }*/
                                //Bitmap noselect = ((CPointLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawnoselect();
                                Temp.Image = ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawlinelayer();
                            }
                            if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CPolygonLayer)
                            {
                                if (draggingc)
                                {
                                    for (int i = 0; i < Controller.Selected.Count(); i++)
                                    {
                                        ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set[Controller.Selected[i]].DragPolygon(move);
                                        //Bitmap bmpnoselect = ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CountLayer - 1]).drawnoselect();
                                        //Temp.Image = ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CountLayer - 1]).drawselectbounds(bmpnoselect);
                                    }
                                }
                                if (draggingsimple)
                                {
                                    ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set[Controller.Selected[0]].Dragsimplepolygon(move);
                                    //Temp.Image = ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawpolygon();
                                }
                                Bitmap bmpnoselect = ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawnoselect();
                                Temp.Image = ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawselectbounds(bmpnoselect);
                            }
                            if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CTextLayer)
                            {
                                if (draggingc)
                                {
                                    for (int i = 0; i < Controller.Selected.Count(); i++)
                                    {
                                        ((CTextLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Text_Set[Controller.Selected[i]].DragCText(move);
                                        ((CTextLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Text_Set[Controller.Selected[i]].updatetextboxes();
                                    }
                                }
                                if (draggingsimple)
                                {
                                    ((CTextLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Text_Set[Controller.Selected[0]].Dragsimpletext(move);
                                    ((CTextLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Text_Set[Controller.Selected[0]].updatetextboxes();
                                }
                                Temp.Image = ((CTextLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawtext();
                            }
                            m_startPoint = new Point(e.X, e.Y);
                        }
                    }
                    if (continuedraw||drawisland)
                    {
                        if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CLineLayer)
                        {
                            if (click)
                            {
                                if (this.m_startPoint.X != e.X && this.m_startPoint.Y != e.Y)
                                {
                                    Temp.Image = ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawLine(m_startPoint, new Point(e.X, e.Y), Controller.Selected[0]);
                                }
                            }
                        }
                        if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CPolygonLayer)
                        {
                            if (click)
                            {
                                if (this.m_startPoint.X != e.X && this.m_startPoint.Y != e.Y)
                                {
                                    //Temp.Image = ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawLine(m_startPoint, new Point(e.X, e.Y), Controller.Selected[0]);
                                    Temp.Image = ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawline(m_startPoint, new Point(e.X, e.Y), Controller.Selected[0]);
                                }
                            }
                        }
                    }
                }
            }

        private void Temp_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (Controller.current_Operation == Controller.OperationStyles.Editing)
            {
                if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CLineLayer || Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CPolygonLayer)
                {
                    dclick = true;
                    click = false;
                    m_startPoint = new Point();
                    if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CLineLayer)
                    {
                        if (Clinelist[current_objectnum].Lines[Clinelist[current_objectnum].Lines.Count() - 1].Count() <= 1)
                        {
                            MessageBox.Show("请点击至少2点才能连成线", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            dclick = false;
                            click = true;
                            m_startPoint = new Point(e.X, e.Y);
                        }
                    }
                    else
                    {
                        if (Controller.snapsameedge != null)
                        {
                            if (Controller.snapsameedge.Count >= 0)
                            {
                                //PointF real_temp = Transformer.FromScreen(new Point(e.X, e.Y));
                                //Cpolygonlist[current_objectnum].addnode(real_temp);
                                Controller.snapsameedge = new List<int>();
                                ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).sign = 0;
                                ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).sign2 = 0;
                            }
                        }
                        int index = ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set.Count() - 1;
                        Temp.Image = ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawnode(dclick, index);
                        //Temp.Image = ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawnode(dclick, current_objectnum);
                        if (Cpolygonlist[current_objectnum].Polygons[Cpolygonlist[current_objectnum].Polygons.Count() - 1].Count() <= 2)
                        {
                            MessageBox.Show("请点击至少3点才能连成多边形", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            dclick = false;
                            click = true;
                            m_startPoint = new Point(e.X, e.Y);
                        }
                    }
                }
            }
            else if (Controller.current_Operation == Controller.OperationStyles.Selecting)
            {
                if (continuedraw||drawisland)
                {
                    dclick = true;
                    click = false;
                    m_startPoint = new Point();
                    if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CLineLayer)
                    {
                        int index = ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Line_Set[Controller.Selected[0]].Lines.Count() - 1;
                        if (((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Line_Set[Controller.Selected[0]].Lines[index].Count() <= 1)
                        {
                            MessageBox.Show("请点击至少2点才能连成线", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            dclick = false;
                            click = true;
                            m_startPoint = new Point(e.X, e.Y);
                        }
                    }
                    if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CPolygonLayer)
                    {
                        if (drawisland&&!addislandpolygon)
                            ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set[Controller.Selected[0]].Polygons.RemoveAt(1);
                        Temp.Image = ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawnode(dclick, Controller.Selected[0]);
                        int index = ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set[Controller.Selected[0]].Polygons.Count() - 1;
                        if (((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set[Controller.Selected[0]].Polygons[index].Count() <= 2)
                        {
                            MessageBox.Show("请点击至少3点才能连成多边形", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            dclick = false;
                            click = true;
                            m_startPoint = new Point(e.X, e.Y);
                        }
                    }
                }
            }
        }


        public bool draggingc = false;
        public bool draggingsimple = false;
        public bool draggingnode = false;

        private void Temp_MouseDown(object sender, MouseEventArgs e)
        {
              if (Controller.current_Operation == Controller.OperationStyles.Zoomin)
             {
                 start_Point.X = e.X;
                 start_Point.Y = e.Y;
                 Move_trails.Clear();
                 Select_position = true;
                 //Pen blackPen = new Pen(Color.Black,2f);
                 //Graphics rec = Temp.CreateGraphics();
                 //rec.DrawRectangle(blackPen, start_Point.X, start_Point.Y, (e.X - start_Point.X), (e.Y - start_Point.Y));
             }
             else if (Controller.current_Operation == Controller.OperationStyles.Zoomout)
             {
                 start_Point.X = e.X;
                 start_Point.Y = e.Y;
                 Move_trails.Clear();
                 Select_position = true;
             }
             else if (Controller.current_Operation == Controller.OperationStyles.Panning)
             {
                 start_Point.X = e.X;
                 start_Point.Y = e.Y;
                 Select_position = true;
                 panselected = true;
                 //Temp.Cursor = Cursors.NoMove2D;
                 p1.X = e.X;
                 p1.Y = e.Y;
             }
            else if (Controller.current_Operation == Controller.OperationStyles.Selecting)
            {
                if (draggingc || draggingsimple)
                {
                    m_startPoint = new Point(e.X, e.Y);
                    isdown = true;
                }
                /*if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CPointLayer)
                {
                    /*PointF real_temp = Viewer.FromScreen(new Point(e.X, e.Y));
                    ((CPointLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).SelectPoint(real_temp);*/
                //noselect = ((CPointLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawnoselect();
                //Temp.Image = ((CPointLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawpoint();
                /*m_startPoint = new Point(e.X, e.Y);
                isdown = true;
            }*/
            }
            else if (Controller.current_Operation == Controller.OperationStyles.Editnode)
            {
                if (draggingnode)
                {
                    m_startPoint = new Point(e.X, e.Y);
                    isdown = true;
                }
            }
        }

        private void Temp_MouseUp(object sender, MouseEventArgs e)
        {
             if (Controller.current_Operation == Controller.OperationStyles.Zoomin)
             {
                 Transformer.Reset(curViewer);
                 
                 end_Point.X = e.X;
                 end_Point.Y = e.Y;
                 Select_position = false;
                 
                 //拉框放大方式
                 if (Math.Abs(end_Point.X - start_Point.X) > 2 || Math.Abs(end_Point.Y - start_Point.Y) > 2)
                 {
                     curViewer.ZoomIn_Multi(start_Point,end_Point);
                     MainForm.pMainWin.toolStripStatusLabelScale.Text = "显示比例：" + curViewer.GetScale().ToString()+"：1";
                     Controller.Draw_Layer(); 
                 }
                 //单点放大
                 else
                 {
                     curViewer.ZoomIn_Point(new Point(e.X, e.Y));
                     MainForm.pMainWin.toolStripStatusLabelScale.Text = "显示比例：" + curViewer.GetScale().ToString()+"：1";
                     Controller.Draw_Layer();    
                 }
             }
             else if (Controller.current_Operation == Controller.OperationStyles.Zoomout)
             {
                 end_Point.X = e.X;
                 end_Point.Y = e.Y;
                 Select_position = false;
                 Transformer.Reset(curViewer);
                 curViewer.ZoomOut(new Point(e.X,e.Y));
                 MainForm.pMainWin.toolStripStatusLabelScale.Text = "显示比例：" + curViewer.GetScale().ToString()+"：1";
                 Controller.Draw_Layer(); 
                     
             }
             else if (Controller.current_Operation == Controller.OperationStyles.Panning)
             {
                 Transformer.Reset(curViewer);
                 end_Point.X = e.X;
                 end_Point.Y = e.Y;
                 Select_position = false;
                 curViewer.Pan(start_Point,end_Point);
                 Controller.Draw_Layer(); 
                 panselected = false;
             }
            else if (Controller.current_Operation == Controller.OperationStyles.Selecting)
            {
                if (draggingc || draggingsimple)
                {
                    isdown = false;
                    if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CPointLayer)
                    {
                        for (int i = 0; i < Controller.Selected.Count(); i++)
                            ((CPointLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Point_Set[Controller.Selected[i]].updateMBR();
                        Temp.Image = ((CPointLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawpoint();
                    }
                    if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CLineLayer)
                    {
                        for (int i = 0; i < Controller.Selected.Count(); i++)
                            ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Line_Set[Controller.Selected[i]].updateMBR();
                        Temp.Image = ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawlinelayer();
                    }
                    if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CPolygonLayer)
                    {
                        for (int i = 0; i < Controller.Selected.Count(); i++)
                            ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set[Controller.Selected[i]].updateMBR();
                        Temp.Image = ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawpolygon();
                    }
                    if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CTextLayer)
                    {
                        for (int i = 0; i < Controller.Selected.Count(); i++)
                            ((CTextLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Text_Set[Controller.Selected[i]].updateMBR();
                        //Temp.Image = ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawpolygon();
                    }

                }
            }
            else if (Controller.current_Operation == Controller.OperationStyles.Editnode)
            {
                if (draggingnode)
                {
                    isdown = false;
                    if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CLineLayer)
                    {
                        for (int i = 0; i < Controller.Selected.Count(); i++)
                            ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Line_Set[Controller.Selected[i]].updateMBR();
                        Temp.Image = ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawlinelayer();
                    }
                    if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CPolygonLayer)
                    {
                        for (int i = 0; i < Controller.Selected.Count(); i++)
                            ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set[Controller.Selected[i]].updateMBR();
                        Temp.Image = ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawpolygon();
                    }
                }
            }
        }
        //点


 
        private void 增加点xyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            addcpoint addpoint = new addcpoint();
            addpoint.ShowDialog();
            addpoint.Close();
        }

         private void 移动到ToolStripMenuItem_Click(object sender, EventArgs e)
         {
             move movepoint = new move();
             movepoint.ShowDialog();
             movepoint.Close();
         }
         private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
         {
             if (continuedraw)
             {
                 ((CPointLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Point_Set[Controller.Selected[0]].updateMBR();
                 continuedraw = false;
             }
             if (canBeCopied)
             {
                 canBeCopied = false;
                 pt_复制ToolStripMenuItem.Enabled = true;
                 pt_粘贴ToolStripMenuItem.Enabled = false;
             }
             if (draggingc)
                 draggingc = false;
             if (draggingsimple)
                 draggingsimple = false;
             if (draggingnode)
                 draggingnode = false;
             if (addnode)
                 addnode = false;
             if (modifytext)
                 modifytext = false;    
             if (MessageBox.Show("确定删除吗？", "删除", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                 {
                     if (Controller.selectsimple != null)
                     {
                         if (Controller.selectsimple.Count > 0)
                         {
                             if (((CPointLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Point_Set.Count() == 1 && Controller.selectsimple.Count() == ((CPointLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Point_Set[Controller.Selected[0]].points.Count())
                             {
                                 if (MessageBox.Show("删除后此图层无点，确定删除吗？", "删除", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                                 {
                                     ((CPointLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Point_Set.RemoveAt(Controller.Selected[0]);
                                     Controller.selectsimple = new List<int>();
                                     selectsimple = false;
                                     Controller.Selected = new List<int>();
                                     MainForm.pMainWin.Edit.Enabled = true;
                                     current_objectnum = 0;
                                     Cpointlist = new List<CPoint>();
                                 }
                             }
                             else if (Controller.selectsimple.Count() == ((CPointLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Point_Set[Controller.Selected[0]].points.Count())
                             {
                                 if (MessageBox.Show("删除后此复杂点对象也被删除，确定删除吗？", "删除", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                                 {
                                     ((CPointLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Point_Set.RemoveAt(Controller.Selected[0]);
                                     current_objectnum = ((CPointLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Point_Set.Count();
                                     Controller.selectsimple = new List<int>();
                                     Controller.Selected = new List<int>();
                                     selectsimple = false;
                                 }
                             }
                             else
                             {
                                 ((CPointLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Point_Set[Controller.Selected[0]].deletesimplepoint();
                                 Controller.selectsimple = new List<int>();
                                 ((CPointLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Point_Set[Controller.Selected[0]].updateMBR();
                             }
                         }
                     }
                     else if (Controller.Selected.Count() > 0)
                     {
                         if (Controller.Selected.Count() == ((CPointLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Point_Set.Count())
                         {
                             if (MessageBox.Show("删除后此图层无点，确定删除吗？", "删除", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                             {
                                 ((CPointLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).DeletePoint();
                                 Controller.Selected = new List<int>();
                                 MainForm.pMainWin.Edit.Enabled = true;
                                 current_objectnum = 0;
                                 Cpointlist = new List<CPoint>();
                             }
                         }
                         else
                         {
                             ((CPointLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).DeletePoint();
                             Controller.Selected = new List<int>();
                             current_objectnum = ((CPointLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Point_Set.Count();
                         }
                     }
                     Temp.Image = ((CPointLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawpoint();
                 }
             else
             {
                 MessageBox.Show("请先选择", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             }
         }
         private void 修改属性ToolStripMenuItem_Click(object sender, EventArgs e)
         {
             ModifyAttribute MApoint = new ModifyAttribute();
             MApoint.ShowDialog();
             MApoint.Close();
         }
        private void 结束编辑ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.Default;
            if (!draggingc&&!continuedraw&&!draggingsimple&&!selectsimple)
            {
                pointobject po = new pointobject();
                CPoint curPoint = ((CPointLayer)Controller.CurrentLayer).Point_Set[((CPointLayer)Controller.CurrentLayer).Point_Set.Count - 1];
                po.NewPO(Controller.CurrentLayer.Name, curPoint.GetID(), curPoint.points.Count);
                if (Controller.CurrentLayer.AttriFields.Count == 0)
                {
                    po.getData().Rows.Add("暂未设置属性字段。");
                }
                else
                {
                    for (int i = 0; i < Controller.CurrentLayer.AttriFields.Count; i++)
                    {
                        po.InitializeField(Controller.CurrentLayer.AttriFields[i][0]);
                    }
                }
                po.ShowDialog();
                if (po.isOK)
                {                 
                    Cpointlist[current_objectnum].updateMBR();
                    current_objectnum++;
                }
                po.isOK = false;
            }
             if (Controller.current_Operation == Controller.OperationStyles.Selecting)
             {
                 if (continuedraw)
                 {
                      ((CPointLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Point_Set[Controller.Selected[0]].updateMBR();
                       continuedraw = false;
                 }
                 else if (draggingc)
                      draggingc = false;
                 else if (draggingsimple)
                     draggingsimple = false;
                 else if (selectsimple)
                 {
                     Controller.selectsimple = new List<int>();
                     selectsimple = false;
                     Temp.Image = ((CPointLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawpoint();
                 }
             }
        }

        //线
         private bool addnode = false;
         private void 增加节点到xyToolStripMenuItem_Click(object sender, EventArgs e)
         {
             addnode = true;
             Controller.selectsimple = new List<int>();
             Controller.current_Operation = Controller.OperationStyles.Editnode;
             if (selectsimple)
             {
                 selectsimple = false;
                 Controller.selectsimple = new List<int>();
                 Temp.Image = ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawlinelayer();
             }
             if (continuedraw)
             {
                 ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Line_Set[Controller.Selected[0]].updateMBR();
                 continuedraw = false;
             }
             if (draggingc)
                 draggingc = false;
             if (draggingsimple)
                 draggingsimple = false;
             if (draggingnode)
                 draggingnode = false;
             if (canBeCopied)
                 canBeCopied = false;
             if (modifytext)
                 modifytext = false;
             /*addnode alinenode = new addnode();
             alinenode.ShowDialog();
             alinenode.Close();*/
         }

         private void 移动偏移量ToolStripMenuItem_Click(object sender, EventArgs e)
         {
             move moveline = new move();
             moveline.ShowDialog();
             moveline.Close();
         }
         private void 删除ToolStripMenuItem1_Click(object sender, EventArgs e)
         {
                   if (Controller.current_Operation == Controller.OperationStyles.Selecting)
                 {
                     if (continuedraw)
                     {
                         continuedraw = false;
                     }
                     if (draggingsimple)
                         draggingsimple = false;
                     if (draggingc)
                         draggingc = false;
                 }                   
            if (Controller.current_Operation == Controller.OperationStyles.Editnode)
            {
                if (addnode)
                {
                    ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Line_Set[Controller.Selected[0]].updateMBR();
                    addnode = false;
                }
                if (draggingnode)
                    draggingnode = false;
            }             
             if (Controller.Selected.Count > 0 || Controller.selectsimple!=null || Controller.current_Operation==Controller.OperationStyles.Editnode)
             {
                 if (MessageBox.Show("确定删除吗？", "删除", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                 {
                     if (Controller.selectnodeindex.X != -1)
                     {
                         if (((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Line_Set[Controller.Selected[0]].Lines[Controller.selectnodeindex.X].Count() == 2)
                         {
                             MessageBox.Show("删除后会成为点，不能删除", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                         }
                         else
                         {
                             if (Controller.selectnodeindex.Y == ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Line_Set[Controller.Selected[0]].Lines[Controller.selectnodeindex.X].Count() - 1)
                             {
                                 ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Line_Set[Controller.Selected[0]].deletenode(Controller.selectnodeindex.X, Controller.selectnodeindex.Y);
                                 Controller.selectnodeindex.Y--;
                             }
                             else
                             {
                                 ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Line_Set[Controller.Selected[0]].deletenode(Controller.selectnodeindex.X, Controller.selectnodeindex.Y);
                             }
                                 ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Line_Set[Controller.Selected[0]].updateMBR();
                         }
                     }
                     else if (Controller.selectsimple.Count > 0)
                     {
                             if (((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Line_Set.Count() == 1 && Controller.selectsimple.Count() == ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Line_Set[Controller.Selected[0]].Lines.Count())
                             {
                                 if (MessageBox.Show("删除后此图层无线，确定删除吗？", "删除",MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                                 {
                                     ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Line_Set.RemoveAt(Controller.Selected[0]);
                                     Controller.selectsimple = new List<int>();
                                     selectsimple = false;
                                     Controller.Selected = new List<int>();
                                     MainForm.pMainWin.Edit.Enabled = true;
                                     current_objectnum = 0;
                                     Clinelist = new List<CLine>();
                                 }
                             }
                             else if( Controller.selectsimple.Count() == ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Line_Set[Controller.Selected[0]].Lines.Count())
                             {
                                 if (MessageBox.Show("删除后此复杂线对象也被删除，确定删除吗？", "删除",MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                                 {
                                     ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Line_Set.RemoveAt(Controller.Selected[0]);
                                     current_objectnum = ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Line_Set.Count();
                                     Controller.selectsimple = new List<int>();
                                     Controller.Selected = new List<int>();
                                     selectsimple = false;
                                 }
                             }
                         else
                         {
                             ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Line_Set[Controller.Selected[0]].deletesimpleline();
                             Controller.selectsimple = new List<int>();
                             ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Line_Set[Controller.Selected[0]].updateMBR();
                         }
                     }
                     else if (Controller.Selected.Count() > 0)
                     {
                         if (Controller.Selected.Count() == ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Line_Set.Count())
                         {
                             if (MessageBox.Show("删除后此图层无线，确定删除吗？", "删除", MessageBoxButtons.OKCancel,MessageBoxIcon.Question) == DialogResult.OK)
                             {
                                 ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).DeleteLine();
                                 Controller.Selected = new List<int>();
                                 MainForm.pMainWin.Edit.Enabled = true;
                                 current_objectnum = 0;
                                 Clinelist = new List<CLine>();
                             }
                         }
                         else
                         {
                             ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).DeleteLine();
                             Controller.Selected = new List<int>();
                             current_objectnum = ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Line_Set.Count();
                         }
                     }
                     /*else if (Controller.selectsimple.Count() > 0)
                     {
                         ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Line_Set[Controller.Selected[0]].deletesimpleline();
                         Controller.selectsimple = new List<int>();
                         ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Line_Set[Controller.Selected[0]].updateMBR();
                     }
                     else if (Controller.Selected.Count > 0)
                     {
                         ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).DeleteLine();
                         Controller.Selected = new List<int>();
                     }*/
                     Temp.Image = ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawlinelayer(); 
                 }
             }
             else
             {
                 MessageBox.Show("请先选择", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             }
         }
         private void 修改属性ToolStripMenuItem1_Click(object sender, EventArgs e)
         {
             ModifyAttribute MAline = new ModifyAttribute();
             MAline.ShowDialog();
             MAline.Close();
         }

        //线对象结束编辑
        private void 结束编辑ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.Default;
            if (Controller.current_Operation != Controller.OperationStyles.Editnode && !draggingsimple && !draggingc && !selectsimple&&!continuedraw)
            {
                lineobject lo = new lineobject();
                CLine curLine = ((CLineLayer)Controller.CurrentLayer).Line_Set[((CLineLayer)Controller.CurrentLayer).Line_Set.Count - 1];
                lo.NewPO(Controller.CurrentLayer.Name, curLine.GetID(), curLine.Lines.Count);
                if (Controller.CurrentLayer.AttriFields.Count == 0)
                {
                    lo.getData().Rows.Add("暂未设置属性字段。");
                }
                else
                {
                    for (int i = 0; i < Controller.CurrentLayer.AttriFields.Count; i++)
                    {
                        lo.InitializeField(Controller.CurrentLayer.AttriFields[i][0]);
                    }
                }
                lo.ShowDialog();
                if (lo.isOK)
                {        
                    Clinelist[current_objectnum].updateMBR();
                    current_objectnum++;
                }
                lo.isOK = false;
            }
                 if (Controller.current_Operation == Controller.OperationStyles.Selecting)
                 {
                     if (continuedraw)
                     {
                         ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Line_Set[Controller.Selected[0]].updateMBR();
                         continuedraw = false;
                     }
                     else if (draggingsimple)
                         draggingsimple = false;
                     else if (draggingc)
                         draggingc = false;
                     else if (selectsimple)
                     {
                         Controller.selectsimple = new List<int>();
                         selectsimple = false;
                         Temp.Image = ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawlinelayer();
                     }
                 }                   
            if (Controller.current_Operation == Controller.OperationStyles.Editnode)
            {
                if (addnode)
                {
                    ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Line_Set[Controller.Selected[0]].updateMBR();
                    addnode = false;
                }
                else if (draggingnode)
                    draggingnode = false;
                else
                {
                    Controller.current_Operation = Controller.OperationStyles.Selecting;
                    Controller.selectlineindex = new Point(-1, -1);
                    Controller.selectnodeindex = new Point(-1, -1);
                    Temp.Image = ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawlinelayer();
                }
            }
        }

        //面
         private void 增加节点到xyToolStripMenuItem1_Click(object sender, EventArgs e)
         {
             /*addnode apolygonnode = new addnode();
             apolygonnode.ShowDialog();
             apolygonnode.Close();*/
             addnode = true;
         }

         private void 移动偏移量ToolStripMenuItem1_Click(object sender, EventArgs e)
         {
             move movepolygon = new move();
             movepolygon.ShowDialog();
             movepolygon.Close();
         }
         private void 删除ToolStripMenuItem4_Click(object sender, EventArgs e)
         {
             if (Controller.current_Operation == Controller.OperationStyles.Selecting)
             {
                 if (continuedraw)
                 {
                     continuedraw = false;
                 }
                 if (draggingc)
                     draggingc = false;
                 if (draggingsimple)
                     draggingsimple = false;
                 if (drawisland)
                 {
                     drawisland = false;
                     addislandpolygon = false;
                     ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawisland = false;
                 }
             }
             if (Controller.current_Operation == Controller.OperationStyles.Editnode)
             {
                 if (draggingnode)
                     draggingnode = false;
             }
             if (Controller.Selected.Count > 0 || Controller.selectsimple.Count > 0 || Controller.selectnodeindex.X != -1)
             {
                 if (MessageBox.Show("确定删除吗？", "删除", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                 {
                     if (Controller.current_Operation == Controller.OperationStyles.Editnode)
                     {
                         if (Controller.selectnodeindex.X != -1)
                         {
                             if (((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set[Controller.Selected[0]].Polygons[Controller.selectnodeindex.X].Count() == 3)
                             {
                                 MessageBox.Show("删除后会成为线，不能删除", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                             }
                             else
                             {
                                 if (Controller.selectnodeindex.Y == ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set[Controller.Selected[0]].Polygons[Controller.selectnodeindex.X].Count() - 1)
                                 {
                                     ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set[Controller.Selected[0]].deletenode(Controller.selectnodeindex.X, Controller.selectnodeindex.Y);
                                     Controller.selectnodeindex.Y--;
                                 }
                                 else
                                 {
                                     ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set[Controller.Selected[0]].deletenode(Controller.selectnodeindex.X, Controller.selectnodeindex.Y);
                                 }
                                 ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set[Controller.Selected[0]].updateMBR();
                             }
                         }
                     }
                     else if (Controller.selectsimple != null)
                     {
                         if (Controller.selectsimple.Count > 0)
                         {
                             if (((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set.Count() == 1 && Controller.selectsimple.Count() == ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set[Controller.Selected[0]].Polygons.Count())
                             {
                                 if (MessageBox.Show("删除后此图层无多边形，确定删除吗？", "删除", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                                 {
                                     ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set.RemoveAt(Controller.Selected[0]);
                                     Controller.selectsimple = new List<int>();
                                     selectsimple = false;
                                     Controller.Selected = new List<int>();
                                     MainForm.pMainWin.Edit.Enabled = true;
                                     current_objectnum = 0;
                                     Cpolygonlist = new List<CPolygon>();
                                 }
                             }
                             else if (Controller.selectsimple.Count() == ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set[Controller.Selected[0]].Polygons.Count())
                             {
                                 if (MessageBox.Show("删除后此复杂多边形对象也被删除，确定删除吗？", "删除", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                                 {
                                     ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set.RemoveAt(Controller.Selected[0]);
                                     current_objectnum = ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set.Count();
                                     Controller.selectsimple = new List<int>();
                                     Controller.Selected = new List<int>();
                                     selectsimple = false;
                                 }
                             }
                             else
                             {
                                 ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set[Controller.Selected[0]].deletesimplepolygon();
                                 Controller.selectsimple = new List<int>();
                                 ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set[Controller.Selected[0]].updateMBR();
                             }
                         }
                     }
                     else if (Controller.Selected.Count() > 0)
                     {
                         if (Controller.Selected.Count() == ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set.Count())
                         {
                             if (MessageBox.Show("删除后此图层无多边形，确定删除吗？", "删除", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                             {
                                 ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).DeletePolygon();
                                 Controller.Selected = new List<int>();
                                 MainForm.pMainWin.Edit.Enabled = true;
                                 current_objectnum = 0;
                                 Cpolygonlist = new List<CPolygon>();
                             }
                         }
                         else
                         {
                             ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).DeletePolygon();
                             Controller.Selected = new List<int>();
                             current_objectnum = ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set.Count();
                         }
                     } 
                     Temp.Image = ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawpolygon();
                 }
             }
             else
             {
                 MessageBox.Show("请先选择", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             }
         }
         private void 修改属性ToolStripMenuItem2_Click(object sender, EventArgs e)
         {
             ModifyAttribute MApolygon = new ModifyAttribute();
             MApolygon.ShowDialog();
             MApolygon.Close();
         }

        //面对象结束编辑
        private void 结束编辑ToolStripMenuItem3_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.Default;
            if (Controller.current_Operation != Controller.OperationStyles.Editnode && !draggingc && !draggingsimple && !selectsimple&&!continuedraw&&!drawisland)
            {
                polygonobject plo = new polygonobject();
                CPolygon curPolygon = ((CPolygonLayer)Controller.CurrentLayer).Polygon_Set[((CPolygonLayer)Controller.CurrentLayer).Polygon_Set.Count - 1];
                plo.NewPO(Controller.CurrentLayer.Name, curPolygon.GetID(), curPolygon.Polygons.Count);
                if (Controller.CurrentLayer.AttriFields.Count == 0)
                {
                    plo.getData().Rows.Add("暂未设置属性字段。");
                }
                else
                {
                    for (int i = 0; i < Controller.CurrentLayer.AttriFields.Count; i++)
                    {
                        plo.InitializeField(Controller.CurrentLayer.AttriFields[i][0]);
                    }
                }
                plo.ShowDialog();
                if (plo.isOK)
                {
                    /*if (Controller.current_Operation == Controller.OperationStyles.Selecting)
                    {
                        //MainForm.pMainWin.Drag.Enabled = true;                      
                        if (continuedraw)
                            ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set[Controller.Selected[0]].updateMBR();
                    }
                    continuedraw = false;*/
                    Cpolygonlist[current_objectnum].updateMBR();
                    current_objectnum++;
                }
                plo.isOK = false;
            }
                 if (Controller.current_Operation == Controller.OperationStyles.Selecting)
                    {                    
                        if (continuedraw)
                        {
                            ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set[Controller.Selected[0]].updateMBR();
                            continuedraw = false;
                        }
                        else if (draggingc)
                            draggingc = false;
                        else if (draggingsimple)
                            draggingsimple = false;
                        else if (selectsimple)
                        {
                            selectsimple = false;
                            Controller.selectsimple = new List<int>();
                            Temp.Image = ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawpolygon();
                        }
                        if (drawisland)
                        {
                            drawisland = false;
                            addislandpolygon = false;
                            ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawisland = false;
                        }
                 }
            if (Controller.current_Operation == Controller.OperationStyles.Editnode)
            {
                if (addnode)
                {
                    ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set[Controller.Selected[0]].updateMBR();
                    addnode = false;
                }
                else if (draggingnode)
                    draggingnode = false;
                else
                {
                    Controller.current_Operation = Controller.OperationStyles.Selecting;
                    Controller.selectlineindex = new Point(-1, -1);
                    Controller.selectnodeindex = new Point(-1, -1);
                    Temp.Image = ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawpolygon();
                }
            }
        }

        //文本
         private void 增加文本到xyToolStripMenuItem_Click(object sender, EventArgs e)
         {
             addtext addt = new addtext();
             addt.ShowDialog();
             addt.Close();
         }

         private void 移动textToolStripMenuItem2_Click(object sender, EventArgs e)
         {
             move movetext = new move();
             movetext.ShowDialog();
             movetext.Close();
         }
         private void 删除ToolStripMenuItem3_Click(object sender, EventArgs e)
         {
             if (Controller.current_Operation == Controller.OperationStyles.Selecting)
             {
                 if (continuedraw)
                 {
                     continuedraw = false;
                     MainForm.pMainWin.TextEdit.Enabled = false;
                     MainForm.pMainWin.TextEdit.Text = "";
                 }
                 if (draggingc)
                     draggingc = false;
                 if (draggingsimple)
                     draggingsimple = false;
                 if (modifytext)
                 {
                     modifytext = false;
                     MainForm.pMainWin.TextEdit.Text = "";
                     MainForm.pMainWin.TextEdit.Enabled = false;
                 }
             }                  
             if (Controller.Selected.Count > 0 || Controller.selectsimple!=null )
             {
                 if (MessageBox.Show("确定删除吗？", "删除", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                 {
                     if (Controller.selectsimple.Count > 0)
                     {
                         if (((CTextLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Text_Set.Count() == 1 && Controller.selectsimple.Count() == ((CTextLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Text_Set[Controller.Selected[0]].points.Count())
                         {
                             if (MessageBox.Show("删除后此图层无文本，确定删除吗？", "删除", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                             {
                                 ((CTextLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Text_Set.RemoveAt(Controller.Selected[0]);
                                 Controller.selectsimple = new List<int>();
                                 selectsimple = false;
                                 Controller.Selected = new List<int>();
                                 MainForm.pMainWin.Edit.Enabled = true;
                                 current_objectnum = 0;
                                 Ctextlist = new List<CText>();
                             }
                         }
                         else if (Controller.selectsimple.Count() == ((CTextLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Text_Set[Controller.Selected[0]].points.Count())
                         {
                             if (MessageBox.Show("删除后此复杂文本对象也被删除，确定删除吗？", "删除", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                             {
                                 ((CTextLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Text_Set.RemoveAt(Controller.Selected[0]);
                                 current_objectnum = ((CTextLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Text_Set.Count();
                                 Controller.selectsimple = new List<int>();
                                 Controller.Selected = new List<int>();
                                 selectsimple = false;
                             }
                         }
                         else
                         {
                             ((CTextLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Text_Set[Controller.Selected[0]].Deletesimpletext();
                             Controller.selectsimple = new List<int>();
                             ((CTextLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Text_Set[Controller.Selected[0]].updateMBR();
                         }
                     }
                     else if (Controller.Selected.Count() > 0)
                     {
                         if (Controller.Selected.Count() == ((CTextLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Text_Set.Count())
                         {
                             if (MessageBox.Show("删除后此图层无文本，确定删除吗？", "删除", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                             {
                                 ((CTextLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).DeleteText();
                                 Controller.Selected = new List<int>();
                                 MainForm.pMainWin.Edit.Enabled = true;
                                 current_objectnum = 0;
                                 Ctextlist = new List<CText>();
                             }
                         }
                         else
                         {
                             ((CTextLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).DeleteText();
                             Controller.Selected = new List<int>();
                             current_objectnum = ((CTextLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Text_Set.Count();
                         }
                     }
                     Temp.Image = ((CTextLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawtext();     
                 }
             }
             else
             {
                 MessageBox.Show("请先选择", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             }
         }

         private void 修改属性ToolStripMenuItem3_Click(object sender, EventArgs e)
         {
             ModifyAttribute MAtext = new ModifyAttribute();
             MAtext.ShowDialog();
             MAtext.Close();
         }
         private void 结束编辑ToolStripMenuItem2_Click(object sender, EventArgs e)
         {
             this.Cursor = Cursors.Default;
             if (Controller.current_Operation != Controller.OperationStyles.Editnode && !draggingc && !draggingsimple && !selectsimple&&!modifytext&&!continuedraw)
             {
                 textobject to = new textobject();
                 CText curText = ((CTextLayer)Controller.CurrentLayer).Text_Set[((CTextLayer)Controller.CurrentLayer).Text_Set.Count - 1];
                 to.NewPO(Controller.CurrentLayer.Name, curText.GetID(), curText.texts.Count);
                 if (Controller.CurrentLayer.AttriFields.Count == 0)
                 {
                     to.getData().Rows.Add("暂未设置属性字段。");
                 }
                 else
                 {
                     for (int i = 0; i < Controller.CurrentLayer.AttriFields.Count; i++)
                     {
                         to.InitializeField(Controller.CurrentLayer.AttriFields[i][0]);
                     }
                 }
                 to.ShowDialog();
                 if (to.isOK)
                 {
                     /*if (Controller.current_Operation == Controller.OperationStyles.Selecting)
                     {
                         //MainForm.pMainWin.Drag.Enabled = true;
                         if (continuedraw)
                             ((CTextLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Text_Set[Controller.Selected[0]].updateMBR();
                     }
                     continuedraw = false;*/
                     Ctextlist[current_objectnum].updateMBR();
                     MainForm.pMainWin.TextEdit.Text = "";
                     current_objectnum++;
                 }
                 to.isOK = false;
             }
             if (Controller.current_Operation == Controller.OperationStyles.Selecting)
             {
                 //MainForm.pMainWin.Drag.Enabled = true;
                 if (continuedraw)
                 {
                     ((CTextLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Text_Set[Controller.Selected[0]].updateMBR();
                     continuedraw = false;
                     MainForm.pMainWin.TextEdit.Enabled = false;
                     MainForm.pMainWin.TextEdit.Text = "";
                 }
                 else if (draggingc)
                     draggingc = false;
                 else if (draggingsimple)
                     draggingsimple = false;
                 else if (selectsimple && !modifytext)
                 {
                     selectsimple = false;
                     Controller.selectsimple = new List<int>();
                     Temp.Image = ((CTextLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawtext();
                 }
                 else if (modifytext)
                 {
                     modifytext = false;
                     MainForm.pMainWin.TextEdit.Text = "";
                     MainForm.pMainWin.TextEdit.Enabled = false;
                     //修改文本ToolStripMenuItem.Enabled = false;
                 }
             }                                
         }
         private void pt_继续画ToolStripMenuItem_Click(object sender, EventArgs e)
         {
             if (Controller.Selected.Count() == 1)
             {
                 continuedraw = true;
                 if (selectsimple)
                 {
                     Controller.selectsimple = new List<int>();
                     selectsimple = false;
                     Temp.Image = ((CPointLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawpoint();
                 }
                 if (draggingc)
                     draggingc = false;
                 if (draggingsimple)
                     draggingsimple = false;
                 if (draggingnode)
                     draggingnode = false;
                 if (canBeCopied)
                 {
                     canBeCopied = false;
                     pt_复制ToolStripMenuItem.Enabled = true;
                     pt_粘贴ToolStripMenuItem.Enabled = false;
                 }
                 if (addnode)
                     addnode = false;
                 if (modifytext)
                     modifytext = false;
                 Controller.selectlineindex = new Point(-1, -1);
                 Controller.selectnodeindex = new Point(-1, -1);
                 MainForm.pMainWin.Drag.Enabled= false;
             }
             else
                 MessageBox.Show("请选择仅一个复杂点对象才能继续编辑", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }

         private void ln_继续画ToolStripMenuItem1_Click(object sender, EventArgs e)
         {
             if (Controller.Selected.Count() == 1)
             {
                 if (Controller.current_Operation == Controller.OperationStyles.Editnode)
                 {
                     Controller.selectlineindex = new Point(-1, -1);
                     Controller.selectnodeindex = new Point(-1, -1);
                     Controller.current_Operation = Controller.OperationStyles.Selecting;
                     Temp.Image = ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawlinelayer();
                 }
                 Controller.current_Operation = Controller.OperationStyles.Selecting;
                 continuedraw = true;
                 MainForm.pMainWin.Drag.Enabled = false;
                 if (selectsimple)
                 {
                     selectsimple = false;
                     Controller.selectsimple = new List<int>();
                     Temp.Image = ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawlinelayer();
                 }
                 if (draggingc)
                     draggingc = false;
                 if (draggingsimple)
                     draggingsimple = false;
                 if (draggingnode)
                     draggingnode = false;
                 if (canBeCopied)
                     canBeCopied = false;
                 if (addnode)
                 {
                     addnode = false;
                     ln_增加节点到xyToolStripMenuItem.Enabled = false;
                     ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Line_Set[Controller.Selected[0]].updateMBR();
                 }
                 if (modifytext)
                     modifytext = false;
             }
             else
                 MessageBox.Show("请选择仅一个复杂线对象才能继续编辑", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
         //public bool editnode;
         private void ln_编辑节点ToolStripMenuItem_Click(object sender, EventArgs e)
         {
             if (Controller.Selected.Count() == 1)
             {
                 Controller.selectlineindex = new Point(-1, -1);
                 Controller.selectnodeindex = new Point(-1, -1);
                 Controller.current_Operation = Controller.OperationStyles.Editnode;
                 if (selectsimple)
                 {
                     selectsimple = false;
                     Controller.selectsimple = new List<int>();
                     Temp.Image = ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawlinelayer();
                 }
                 if (continuedraw)
                 {
                     ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Line_Set[Controller.Selected[0]].updateMBR();
                     continuedraw = false;
                 }
                 if (draggingc)
                     draggingc = false;
                 if (draggingsimple)
                     draggingsimple = false;
                 if (draggingnode)
                     draggingnode = false;
                 if (canBeCopied)
                     canBeCopied = false;
                 if (addnode)
                 {
                     addnode = false;
                     ln_增加节点到xyToolStripMenuItem.Enabled = false;
                     ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Line_Set[Controller.Selected[0]].updateMBR();
                 }
                 if (modifytext)
                     modifytext = false;
                 Temp.Image = ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID-1]).drawlinelayer();
             }
             else
                 MessageBox.Show("请选择仅一个复杂线对象才能编辑节点", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }


        /*private void 结束编辑ToolStripMenuItem2_Click(object sender, EventArgs e)
        {
            textobject to = new textobject();
            CText curText = ((CTextLayer)Controller.CurrentLayer).Text_Set[((CTextLayer)Controller.CurrentLayer).Text_Set.Count - 1];
            to.NewPO(Controller.CurrentLayer.Name, curText.GetID(), curText.texts.Count);
            if (Controller.CurrentLayer.AttriFields.Count == 0)
            {
                to.getData().Rows.Add("暂未设置属性字段。");
            }
            else
            {
                for (int i = 0; i < Controller.CurrentLayer.AttriFields.Count; i++)
                {
                    to.InitializeField(Controller.CurrentLayer.AttriFields[i][0]);
                }
            } 
            to.ShowDialog();
            if (to.isOK)
            {
                /*if (Controller.current_Operation == Controller.OperationStyles.Selecting)
                    MainForm.pMainWin.Drag.Enabled = true; 
                continuedraw = false;
                Ctextlist[current_objectnum].updateMBR();
                Ctextlist[current_objectnum].getsizes();
                current_objectnum++;
            }
            to.isOK = false;
        }*/
         private bool canBeCopied = false;
         private void pt_复制ToolStripMenuItem_Click(object sender, EventArgs e)
         {
             pt_粘贴ToolStripMenuItem.Enabled = true;
             canBeCopied = true;
             int SelectedTag = Controller.Selected[Controller.Selected.Count - 1];
             if (continuedraw)
             {
                 ((CPointLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Point_Set[Controller.Selected[0]].updateMBR();
                 continuedraw = false;
             }
             if (selectsimple)
             {
                 Controller.selectsimple = new List<int>();
                 selectsimple = false;
                 Temp.Image = ((CPointLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawpoint();
             }
             if (draggingc)
                 draggingc = false;
             if (draggingsimple)
                 draggingsimple = false;
             if (draggingnode)
                 draggingnode = false;
             if (addnode)
                 addnode = false;
             if (modifytext)
                 modifytext = false;
             Controller.selectlineindex = new Point(-1, -1);
             Controller.selectnodeindex = new Point(-1, -1);
         }

         private void pt_粘贴ToolStripMenuItem_Click(object sender, EventArgs e)
         {
             if (Controller.CurrentLayer.Layer_Type == CLayer.LayerType.CPointLayer)
             {
                 List<PointF> tempPoints = new List<PointF>();
                 for (int i = 0; i < Controller.Selected.Count; i++)
                 {
                     CPoint needCopyPoint = new CPoint();
                     needCopyPoint = ((CPointLayer)Controller.MyMap.Layer_List[Controller.CurrentID-1]).Point_Set[Controller.Selected[i]];
                     for (int j = 0; j < needCopyPoint.points.Count; j++)
                     {
                         //tempPoints记录要复制的图形对象的所有点，供计算MBR
                         tempPoints.Add(needCopyPoint.points[j]);
                     }
                 }
                 MBR thisMBR = new MBR();
                 thisMBR.GetMBR(tempPoints);
                 float MBRcenterX, MBRcenterY;
                 MBRcenterX = (thisMBR.Lx + thisMBR.Rx) / 2;
                 MBRcenterY = (thisMBR.Ly + thisMBR.Ry) / 2;
                 float offsetX, offsetY;
                 PointF real_CopyToLoc = Transformer.FromScreen(CopyToLoc);
                 //重新计算粘贴后的点对象坐标
                 offsetX = real_CopyToLoc.X - MBRcenterX;
                 offsetY = real_CopyToLoc.Y - MBRcenterY;
                  for (int i = 0; i < Controller.Selected.Count; i++)
                 {
                     CPoint needCopyPoint = new CPoint();
                     needCopyPoint = ((CPointLayer)Controller.MyMap.Layer_List[Controller.CurrentID-1]).Point_Set[Controller.Selected[i]];
                     List<PointF> tempList = new List<PointF>();
                     for (int j = 0; j < needCopyPoint.points.Count; j++)
                     {
                         tempList.Add(new PointF(needCopyPoint.points[j].X + offsetX, needCopyPoint.points[j].Y + offsetY));
                     }
                     CPoint CopyPoint = new CPoint();
                     CopyPoint.newCpoint(IDGenerator.PointID(), needCopyPoint.LegendID);
                     CopyPoint.points = tempList;
                     CopyPoint.MinBR.GetMBR(CopyPoint.points);
                     ((CPointLayer)Controller.MyMap.Layer_List[Controller.CurrentID-1]).Point_Set.Add(CopyPoint);
                 }

                 Temp.Image = ((CPointLayer)Controller.MyMap.Layer_List[Controller.CurrentID-1]).drawpoint();
             }

         }

         public bool selectsimple = false;
         private void ln_选择简单线ToolStripMenuItem_Click(object sender, EventArgs e)
         {
             if (Controller.Selected.Count() == 1)
             {
                 if (Controller.current_Operation == Controller.OperationStyles.Editnode)
                 {
                     Controller.selectlineindex = new Point(-1, -1);
                     Controller.selectnodeindex = new Point(-1, -1);
                     Controller.current_Operation = Controller.OperationStyles.Selecting;
                     Temp.Image = ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawlinelayer();
                 }
                 Controller.current_Operation = Controller.OperationStyles.Selecting;
                 selectsimple = true;
                 Controller.selectsimple = new List<int>();
                 if (continuedraw)
                 {
                     ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Line_Set[Controller.Selected[0]].updateMBR();
                     continuedraw = false;
                 }
                 if (draggingc)
                     draggingc = false;
                 if (draggingsimple)
                     draggingsimple = false;
                 if (draggingnode)               
                     draggingnode = false;
                 if (canBeCopied)
                     canBeCopied = false;
                 if (addnode)
                 {
                     addnode = false;
                     ln_增加节点到xyToolStripMenuItem.Enabled = false;
                     ((CLineLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Line_Set[Controller.Selected[0]].updateMBR();
                 }
                 if (modifytext)
                     modifytext = false;
             }
             else
                 MessageBox.Show("请选择仅一个复杂线对象才能选择简单线", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }

         private void plgn_继续画ToolStripMenuItem2_Click(object sender, EventArgs e)
         {
             if (Controller.Selected.Count() == 1)
             {
                 if (Controller.current_Operation == Controller.OperationStyles.Editnode)
                 {
                     Controller.selectlineindex = new Point(-1, -1);
                     Controller.selectnodeindex = new Point(-1, -1);
                     Controller.current_Operation = Controller.OperationStyles.Selecting;
                     Temp.Image=((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawpolygon();
                 }
                 Controller.current_Operation = Controller.OperationStyles.Selecting;
                 continuedraw = true;
                 MainForm.pMainWin.Drag.Enabled = false;
                 if (selectsimple)
                 {
                     selectsimple = false;
                     Controller.selectsimple = new List<int>();
                     Temp.Image = ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawpolygon();
                 }
                 if (drawisland)
                 {
                     drawisland = false;
                     addislandpolygon = false;
                     ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawisland = false;
                 }
                 if (draggingc)
                     draggingc = false;
                 if (draggingsimple)
                     draggingsimple = false;
                 if (draggingnode)
                     draggingnode = false;
                 if (canBeCopied)
                     canBeCopied = false;
                 if (addnode)
                 {
                     addnode = false;
                     plgn_增加节点到xyToolStripMenuItem1.Enabled = false;
                     ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set[Controller.Selected[0]].updateMBR();
                 }
                 if (modifytext)
                     modifytext = false;
             }
             else
                 MessageBox.Show("请选择仅一个复杂多边形对象才能继续编辑", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }

         private void plgn_选择简单多边形ToolStripMenuItem_Click(object sender, EventArgs e)
         {
             if (Controller.Selected.Count() == 1)
             {
                 if (Controller.current_Operation == Controller.OperationStyles.Editnode)
                 {
                     Controller.selectlineindex = new Point(-1, -1);
                     Controller.selectnodeindex = new Point(-1, -1);
                     Controller.current_Operation = Controller.OperationStyles.Selecting;
                     Temp.Image=((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawpolygon();
                 }
                 Controller.current_Operation = Controller.OperationStyles.Selecting;
                 selectsimple = true;
                 Controller.selectsimple = new List<int>();
                 //Controller.selectlineindex = new Point(-1, -1);
                 //Controller.selectnodeindex = new Point(-1, -1);
                 if (continuedraw)
                 {
                     ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set[Controller.Selected[0]].updateMBR();
                     continuedraw = false;
                 }
                 if (drawisland)
                 {
                     drawisland = false;
                     addislandpolygon = false;
                     ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawisland = false;
                 }
                 if (draggingc)
                     draggingc = false;
                 if (draggingsimple)
                     draggingsimple = false;
                 if (draggingnode)
                     draggingnode = false;
                 if (canBeCopied)
                     canBeCopied = false;
                 if (addnode)
                 {
                     addnode = false;
                     plgn_增加节点到xyToolStripMenuItem1.Enabled = false;
                     ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set[Controller.Selected[0]].updateMBR();
                 }
                 if (modifytext)
                     modifytext = false;
             }
             else
                 MessageBox.Show("请选择仅一个复杂多边形对象才能选择简单多边形", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }

         private void plgn_编辑节点ToolStripMenuItem1_Click(object sender, EventArgs e)
         {
             if (Controller.Selected.Count() == 1)
             {
                 Controller.selectlineindex = new Point(-1, -1);
                 Controller.selectnodeindex = new Point(-1, -1);
                 Controller.selectsimple = new List<int>();
                 Controller.current_Operation = Controller.OperationStyles.Editnode;
                 if (selectsimple)
                 {
                     selectsimple = false;
                     Temp.Image = ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawpolygon();
                 }
                 if (drawisland)
                 {
                     drawisland = false;
                     addislandpolygon = false;
                     ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawisland = false;
                 }
                 if (continuedraw)
                 {
                     ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set[Controller.Selected[0]].updateMBR();
                     continuedraw = false;
                 }
                 if (draggingc)
                     draggingc = false;
                 if (draggingsimple)
                     draggingsimple = false;
                 if (draggingnode)
                     draggingnode = false;
                 if (canBeCopied)
                     canBeCopied = false;
                 if (addnode)
                 {
                     addnode = false;
                     plgn_增加节点到xyToolStripMenuItem1.Enabled = false;
                     ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Polygon_Set[Controller.Selected[0]].updateMBR();
                 }
                 if (modifytext)
                     modifytext = false;
                 Temp.Image = ((CPolygonLayer)Controller.MyMap.Layer_List[Controller.CurrentID-1]).drawpolygon();
             }
             else
                 MessageBox.Show("请选择仅一个复杂多边形对象才能编辑节点", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }

         private void tx_继续编辑ToolStripMenuItem_Click(object sender, EventArgs e)
         {
             if (Controller.Selected.Count() == 1)
             {
                 continuedraw = true;
                 MainForm.pMainWin.Drag.Enabled = false;
                 MainForm.pMainWin.TextEdit.Enabled = true;
                 if (draggingc)
                     draggingc = false;
                 if (draggingsimple)
                     draggingsimple = false;
                 if (selectsimple && !modifytext)
                 {
                     selectsimple = false;
                     Controller.selectsimple = new List<int>();
                     Temp.Image = ((CTextLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).drawtext();
                 }
                 if (modifytext)
                 {
                     modifytext = false;
                     MainForm.pMainWin.TextEdit.Text = "";
                     MainForm.pMainWin.TextEdit.Enabled = false;
                 }
                 if (draggingnode)
                     draggingnode = false;
                 if (canBeCopied)
                 {
                     canBeCopied = false;
                 }
                 if (addnode)
                     addnode = false;
                 Controller.selectlineindex = new Point(-1, -1);
                 Controller.selectnodeindex = new Point(-1, -1);
             }
             else
                 MessageBox.Show("请选择仅一个复杂文本对象才能继续编辑", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }

         private void tx_选择简单文本ToolStripMenuItem_Click(object sender, EventArgs e)
         {
             if (Controller.Selected.Count() == 1)
             {
                 Controller.current_Operation = Controller.OperationStyles.Selecting;
                 selectsimple = true;
                 Controller.selectsimple = new List<int>();
                 if (continuedraw)
                 {
                     ((CTextLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Text_Set[Controller.Selected[0]].updateMBR();
                     continuedraw = false;
                     MainForm.pMainWin.TextEdit.Enabled = false;
                     MainForm.pMainWin.TextEdit.Text = "";
                 }
                 if (draggingc)
                     draggingc = false;
                 if (draggingsimple)
                     draggingsimple = false;
                 if (modifytext)
                 {
                     modifytext = false;
                     MainForm.pMainWin.TextEdit.Text = "";
                     MainForm.pMainWin.TextEdit.Enabled = false;;
                 }
                 if (draggingnode)
                     draggingnode = false;
                 if (canBeCopied)
                 {
                     canBeCopied = false;
                 }
                 if (addnode)
                     addnode = false;
                 Controller.selectlineindex = new Point(-1, -1);
                 Controller.selectnodeindex = new Point(-1, -1);
             }
             else
                 MessageBox.Show("请选择仅一个复杂文本对象才能选择简单文本", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }

         private bool modifytext = false;
         private void 修改文本ToolStripMenuItem_Click(object sender, EventArgs e)
         {
             modifytext=true;
             MainForm.pMainWin.TextEdit.Enabled = true;
             if (continuedraw)
             {
                 ((CTextLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Text_Set[Controller.Selected[0]].updateMBR();
                 continuedraw = false;
                 MainForm.pMainWin.TextEdit.Enabled = false;
                 MainForm.pMainWin.TextEdit.Text = "";
             }
             if (draggingc)
                 draggingc = false;
             if (draggingsimple)
                 draggingsimple = false;
             if (draggingnode)
                 draggingnode = false;
             if (canBeCopied)
             {
                 canBeCopied = false;
             }
             if (addnode)
                 addnode = false;
             Controller.selectlineindex = new Point(-1, -1);
             Controller.selectnodeindex = new Point(-1, -1);
         }

         private void pt_选择简单点ToolStripMenuItem_Click(object sender, EventArgs e)
         {
             if (Controller.Selected.Count() == 1)
             {
                 Controller.current_Operation = Controller.OperationStyles.Selecting;
                 selectsimple = true;
                 Controller.selectsimple = new List<int>();
                 if (continuedraw)
                 {
                     ((CPointLayer)Controller.MyMap.Layer_List[Controller.CurrentID - 1]).Point_Set[Controller.Selected[0]].updateMBR();
                     continuedraw = false;
                 }
                 if (draggingc)
                     draggingc = false;
                 if (draggingsimple)
                     draggingsimple = false;
                 if(draggingnode)
                    draggingnode = false;
                 if (canBeCopied)
                 {
                     canBeCopied = false;
                     pt_复制ToolStripMenuItem.Enabled = true;
                     pt_粘贴ToolStripMenuItem.Enabled = false;
                 }
                 if(addnode)
                    addnode = false;
                 if(modifytext)
                    modifytext = false;
                 Controller.selectlineindex = new Point(-1, -1);
                 Controller.selectnodeindex = new Point(-1, -1);
             }
             else
                 MessageBox.Show("请选择仅一个复杂点对象才能选择简单点", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
    }
}
